package huxibianjie.com.lbscandroid.util;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.text.TextUtils;

public class Utils {
    //当前应用是否处于前台
    public static boolean isForeground(Context context) {
        if (context != null) {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
            String currentPackageName = cn.getPackageName();
            if (!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(context.getPackageName())) {
                return true;
            }
            return false;
        }
        return false;
    }

    public static String starPhone(String phone) {
        if (phone != null) {
            if (phone.length() == 11) {
                return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
            } else {
                return phone;
            }
        }
        return "";
    }
}
